package com.teamwork.module03.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.teamwork.common.entity.common.User;
import com.teamwork.module03.mapper.UserIconMapper;
import com.teamwork.module03.service.UserIconService;
import com.teamwork.common.entity.common.UserIcon;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserIconServiceImpl extends ServiceImpl<UserIconMapper, UserIcon> implements UserIconService {
    @Override
    public boolean deleteByUserId(Integer id) {
        LambdaQueryWrapper<UserIcon> wrapper =new LambdaQueryWrapper<>();
        wrapper.eq(UserIcon::getUserId,id);
        boolean b = this.remove(wrapper);
        if(b){
            log.info("根据用户id:{} 删除一条图片信息",id);
        }//else log.error("根据用户id:{} 删除图片出错",id);
        return b;

    }

    @Override
    public UserIcon getByUserId(Integer userid) {

        LambdaQueryWrapper<UserIcon> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserIcon::getUserId,userid);

        return  this.getOne(wrapper);
    }

    /**
     * 注册给用户添加一个默认头像
     * @param user
     */
    @Override
    public void insertDefault(User user) {
        Long id = user.getId();

        UserIcon userIcon = new UserIcon();
        userIcon.setUserId(id);
        userIcon.setIcon("http://localhost:8081/api/user/icon/001.jpg");
        this.save(userIcon);


    }
}
